/*//下拉框联动展示	
$("#selectwd").change(function(){
		var val=$("#selectwd").val();
		if(val=="单个主题队列"){
			$("#selectdl").show();
			//获取下拉菜单的单个主题队列option
			$.ajax({
				"url":"/zhgl-jzstyxx-manage/memory/getOptions",
				"type":"POST",
				"dataType":"json",
				"success":function(obj){
					if(obj!=null){
						for(var i=0;i<obj.length;i++){
							$("#selectdl").append("<option id="+obj[i].topicQueueNo+" value="+obj[i].topicQueueName+">"+obj[i].topicQueueName+"</option>");
						}
					}
				}
			});	
		}
		if(val=="总主题队列"){
			$("#selectdl").css('display','none');
		}
	});*/

/*//下拉框进行各主题队列展示	
$("#searchTable").click(function(){
	var val=$("#selectwd").val();
	if(val=="单个主题队列"){
		$("#labfour").html("各主题队列内存占用");
		var val=$("#selectdl option:selected").val();
		var id=$("#selectdl option:selected").attr("id");
		everytopic(id,val);
	}
	if(val=="总主题队列"){
		$("#labfour").html("当前内存占用");
		gettotal();
	}
});*/

//页面启动就调用总体队列图表
$(document).ready(function(){
	//按时间排列的内存占用
	gettotalByTime();
	giveDateByEveryTopic();
});

//按时间排列的内存占用
function gettotalByTime(){
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getDataByDate",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var ti=obj[0];//时间
				var nc=obj[1];//值
				for(var i=0;i<nc.length;i++){//把B换为MB
					var n=nc[i]/1024/1024;
					n=n.toFixed(2);
					nc[i]=n;
				}
			}
			getDataByDate(ti,nc);
		}
	});
}
//以饼图的方式展示各个主题队列当前的占用内存
function giveDateByEveryTopic(){
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/memory/getEveryTopicMemory",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				showMessageByEveryTopic(obj);
			}
		},
		error:function(obj){
//			alert("加载数据失败！请联系管理员");
		}
	});
}
//按时间排列的内存占用
function getDataByDate(ti,nc){
	var bili=(zy/sums*100).toFixed(2);//占用/全部得到占用比例 此时已经是百分比
	//1.总主题队列
	//1.1总主题队列当前内存情况
		//1.1.1总主题队列当前内存情况左图
		if(myChart!=null&&myChart!=""&&myChart!=undefined){
			myChart.dispose();
		}
		myChart= echarts.init(document.getElementById('totalnowleft'));
		myChart.showLoading();
		var option1={
				//表格背景颜色
				backgroundColor:'#10D09F',
				//表格标题
				title : {text : time+'总内存占用实时情况',/*subtext : '单位:  条', */textStyle:{fontSize:14,color:'#000',},x:5,y:10,},
				//提示框，鼠标悬浮交互时的信息提示
			    tooltip : { trigger: 'axis',
			    	formatter:function(a){
			    		return a[0].name+"<br/>"
			    		+a[0].seriesName+":"+a[0].value+"MB<br/>"
			    	}
				},
			    toolbox: {
			        show : true,
			        feature : {
			            mark : {show: true},
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
	/*		    legend:{
			    	data:[{
			    		name:'内存实时占用',
			    		icon:'emptyCircle',
			    		textStyle:{fontWeight:'bold',color:'#67479A'}
			    	}
			    	,{
			    		name:'预警阈值',
			    		icon:'emptyCircle',
			    		textStyle:{fontWeight:'bold',color:'red'}
			    	}],
			    	y:30,
			    },*/
			    dataZoom : { show : false, start : 0,end : 100 },
			    //x轴设计
			    xAxis : [
			        {
			            type : 'value', scale: true,name : '时间',type : 'category',
			    		boundaryGap : false,
						axisLabel:{show:true,textStyle:{color:'#000',},},
						axisLine:{show:false},//x轴线
						axisTick:{show:false,},//x轴上点
						splitLine:{show:false,},//x轴竖线
			            data : ti,
			            nameTextStyle:{color:'#000',},
			        },
			    ],
			    yAxis : [
			        {
			            type : 'value',
			            scale: true,
			            name : '单位：MB',
			           /* boundaryGap: [0.2, 0.2],*/
						axisLabel:{formatter:'{value}',textStyle:{color:'#000',},},
						axisLine:{show:false},//y轴线
						axisTick:{show:false,},//y轴上点
						splitLine:{show:false,},
						min:0,
						max:250,
			        },
			    ],
			    series : [
			        {
			            name:'内存实时占用',
			            type:'line',
						smooth : true,//曲线连接
						lineStyle:{normal:{color:"#67479A",width:2,},},
			            areaStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0,color: '#A998C5' }, {offset: 1, color: 'rgba(0,0,0,0)' }]), }},
			            data:nc,
			            },
	/*		        {
				        name:'预警阈值',
				        type:'line',
				        lineStyle:{normal:{color:"red",width:1,},},
				        data:[0.6,0.6,0.6,0.6,0.6,0.6,0.6],
				        },*/
			            
			    ]
		}
		myChart.hideLoading();	                    
		myChart.setOption(option1);
}

//右图展示各队列的内存占用
function showMessageByEveryTopic(obj){
	//1.1.2总主题队列当前内存情况右图
	if(myChart2!=null&&myChart!=""&&myChart!=undefined){
		myChart2.dispose();
	}
	myChart2= echarts.init(document.getElementById('totalnowright'));
	myChart2.showLoading();
	var option2={
			title : {
		        text: time+'各主题队列内存占用实时情况',
		        textStyle:{fontSize:14,color:'#000',},
		        /*subtext: '纯属虚构',*/
		        x:'left',
		        y:10,
		    },
		    tooltip : {
		        formatter: "{a} <br/>{b} : {c}KB"
		    },
		    toolbox: {
		        show : true,
		        feature : {
		            mark : {show: true},
		            restore : {show: true},
		            saveAsImage : {show: true}
		        }
		    },
		    series : [
		        {
		            name:'主题队列实时队列占用:',
		            type:'pie',
		            radius:'55%',
		            center:['50%','60%'],
		            data:(function(){
		            	var res=[];
		            	var len=obj[0].length;
		            	for(var i=0;i<len;i++){
		            		res.push({
		            			name:obj[0][i],
		            			value:(obj[1][i]/1024).toFixed(2),
		            		});
		            	}
		            	return res;
		            })()
		        }
		    ]
		};

	myChart2.hideLoading();	                    
	myChart2.setOption(option2);
}


